﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>工资上报管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
</head>
<body>
<div id="backDiv" style="float: right; text-align: right;margin: 10px 30px 0px 0px;cursor: pointer;display:none;font-size: 12px;color: deepskyblue" onclick="window.history.go(-1); ">返回</div>
<div style="float: left; margin-top: 10px">
    <from class="layui-form" action="">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label" style="width: auto;">班组名称</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input type="text" id="banzuname" name="banzuname" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label" style="width: auto;">所属劳务公司</label>
                <div class="layui-input-inline" style="width: 130px;">
                    <input type="text" id="companyName" name="companyName" autocomplete="off" class="layui-input">
                </div>
            </div>
            
            <div class="layui-inline">
                <label class="layui-form-label">工资月份</label>
                <div class="layui-input-inline" style="width: 130px;">
                    <input type="text" name="sdate" id="sdate" placeholder="查询工资开始时间" autocomplete="off"  class="layui-input">
                </div>
                <div class="layui-input-inline" style="width: 130px;">
                     <input type="text" name="edate" id="edate" placeholder="查询工资结束时间" autocomplete="off"  class="layui-input">
                </div>
            </div>
            
            <div class="layui-inline">
                <button class="layui-btn layui-btn-normal" data-type="search" id="btnSearch">查询</button>
            </div>
        </div>
    </from>
</div>
<table class="layui-table" lay-filter="tbFliter" id="tbData" style="margin-top: 0px;">
</table>
<script type="text/html" id="barList">
    <!--<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>-->
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="send">工资填报</a>-->
</script>
<script src="../assets/layui/layui.js"></script>
<script>
    layui.config({
        base: '../js/'
    });
    layui.use(['jquery','table','common','laydate'], function () {
        var table = layui.table,
            common=layui.common,
            laydate=layui.laydate,
            $ = layui.jquery,
            active = {
                search: function () {
                    table.reload("tbOptions", {
                        where: {
                            sdate:$("#sdate").val(),
                            edate:$("#edate").val(),
                            banzuname: $("#banzuname").val(),
                            companyName: $("#companyName").val(),
                            page:1
                        }
                    });
                },
                doImport:function () {

                },
                doExport:function () {

                }
            };
        var back=common.getUrlParam("back");
        init();
        function init(){
            if(back=='true'){
                $("#backDiv").show();
            }
        }

        laydate.render({
            elem: '#sdate'
            ,format:'yyyyMM'
            ,type: 'month'
        });
        laydate.render({
            elem: '#edate'
            ,format:'yyyyMM'
            ,type: 'month'
        });
        var op=common.getUrlParam("op");
        var personlist="";
        $.ajax({
            url: "../project/getperson",
            dataType: "json",
            success: function (rtn) {
                if (rtn && rtn.code===0) {
                    personlist= rtn.data;
                }
            }
        });
        //表格初始化
        table.render({
            elem: '#tbData'
            , skin: 'row'
            , url: '../project/banzusendlist'
            , page: true
            , cols: [[
                // {field: 'id', title: '序号', width: 70}
                // , {field: 'projectname', title: '所属项目'}
                // , {field: 'companyname', title: '所属劳务公司'}
                {field: 'banzu_name', title: '班组名称',width:300}
                , {field: 'profession', title: '工种',width: 70}
                , {field: 'datetime', title: '月份',width: 100}
                , {field: 'pay', title: '金额(元)'}
                ,{field: 'paynumber', title: '人数',width: 70}
                // , {field: 'paynumber', title: '涉及人员',templet: function(d) {
                //     var list = d.paynumber.split(",");
                //     var html = "";
                //     for (var i = 0; i < list.length; i++) {
                //         for (var m = 0; m < personlist.length; m++) {
                //             if (list[i] == personlist[m].code) {
                //                 html += personlist[m].name+",";
                //             }
                //         }
                //     }
                //     html=html.substring(0,html.length-1);
                //     return html;
                // }}
                , {
                    field: 'status', title: '状态', templet: function (d) {
                        if (d.status == 1) {
                            return '待审核';
                        } else if (d.status == 2) {
                            return '审核通过';
                        } else if (d.status == 3) {
                            return '审核不通过';
                        }
                        return "";
                    }
                }
                , {field: 'reason', title: '原因', templet: function(d){
                    if(d.reason==null){
                        return '';
                    }else {
                        return '<label title="'+d.reason+'">'+(d.reason.length>10?d.reason.substring(0,10):d.reason)+'</label>';
                    }
                }}
                , {field: 'updateUser', title: '审批人'}
                , {
                    field: 'credentials', title: '凭据', width: 80, templet: function (d) {
                        if(d.credentials!=null)
                        return '<a class="layui-btn layui-btn-warm layui-btn-xs layui-bg-gray" lay-event="file">查看</a>';
                        else return '';
                    }
                }
                , {
                    field: 'operation', title: '操作', width: 80, templet: function (d) {
                        if (d.status == 1) {
                            var html = '';
                            if (op == 1) {
                                html = '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="check">审核</a>';
                            } else {
                                html = '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                            }
                            return html;
                        }
                        return "";
                    }
                }
            ]]
            , limits: [10, 20, 50]
            , where: {
                sdate:$("#sdate").val(),
                edate:$("#edate").val(),
                banzuname: $("#banzuname").val(),
                op: op,
                companyName: $("#companyName").val()
            }
            , id: 'tbOptions'
        });

        table.on('tool(tbFliter)', function (obj) {
            var data = obj.data; //获得当前行数据
            var id = data.id;
            var layEvent = obj.event; //获得 lay-event

            var list = data.paynumber.split(",");
            var html = "";
            for (var i = 0; i < list.length; i++) {
                for (var m = 0; m < personlist.length; m++) {
                    if (list[i] == personlist[m].code) {
                        html += personlist[m].name+",";
                    }
                }
            }
            html=html.substring(0,html.length-1);

           if (layEvent === 'del') { //删除
                layer.confirm('您确定删除该上报申请吗？', function (index) {
                    $.ajax({
                        type: 'POST',
                        url: '../project/deletebanzusend',
                        dataType: 'json',
                        data: {id: id},
                        success: function (rtn) {
                            if (rtn.code == 0) {
                                common.showMsg('操作成功!');
                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                            }
                            else {
                                common.showError("操作失败:" + rtn.msg);
                            }
                        },
                        error: function () {
                            common.showError("操作失败");
                        }
                    });
                });
            }else  if (layEvent === 'check') {
               common.layer_show("工资上报审批", 'projectCompSendCheck.html?id=' + id+"&namelist="+encodeURIComponent(html),'100%','100%');
           }
           else if(layEvent==='file'){
               common.layer_show("凭据查看", '../person/cdFile.html?fileNames=' + encodeURIComponent(data.credentials)+"&filePt=credentialsBZ",'50%','80%');
           }
        });

        //按钮事件绑定
        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>